package net.sf.brutil.v0.light;

import java.util.Map;

public class MiscUtil {

	public static String buildUrl(String path,Map<String,String[]> parameters){
		StringBuilder retVal=new StringBuilder(path);
		
		int i=0;
		for(String paramName:parameters.keySet()){
			String[] values=parameters.get(paramName);
			for (String value:values){
				
				if (i==0)
					retVal.append("?");
				else
					retVal.append("&");
				retVal.append(paramName);
				retVal.append("=");
				
				
				
				retVal.append(EscapeUtil.escapeUrl(value));
				i++;
			}
		}
		return retVal.toString();
	}
	
	public static String getFileNameExtension(String fileName){
		return getFileNameNameAndExtension(fileName).getB();
	}
    
	  public static Pair<String,String> getFileNameNameAndExtension(String fileName){
		   Pair<String, String> retVal;
		   int idx=fileName.lastIndexOf('.');
		   if (idx==-1) retVal=new Pair<String, String>(fileName,"");
		   else
			   retVal=new Pair<String,String>(fileName.substring(0,idx),fileName.substring(idx+1));
		   return retVal;
		   
	   }
	
	
}
